package com.roncoo.education;
import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
 * 
* @Title: KindoObjectMapper.java 
* @Package com.roncoo.education 
* @Description: 返回前端null值全部转换自定义的  
* @author 刘伟  15818570028@163.com   
* @date 2017年1月11日 上午11:14:04 
* @version V1.0
 */
public class KindoObjectMapper extends ObjectMapper {

    /**
    * 
    */
    private static final long serialVersionUID = 1L;

    public KindoObjectMapper() {
        super();
        // 数字也加引号
        // this.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
        // this.configure(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS,
        // true);
        // 空值处理为空串
        this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
            @Override
            public void serialize(Object value, JsonGenerator jg, SerializerProvider sp)
                    throws IOException, JsonProcessingException {
                jg.writeString("");
            }
        });

    }

}